/* Copyright ©, 2023, ECARX (Hubei) Technology Co., Ltd. All rights reserved.
 *
 * NOTICE: This file contains information which is confidential and proprietary to ECARX
 * (Hubei) Technology Co., Ltd. and/or other developers. No license to any intellectual
 * property rights contained within this file is either granted or implied except as may be
 * provided in an agreement with ECARX (Hubei) Technology Co., Ltd.
 *
 * Any unauthorized copying or distribution of content from this file in whole or in part
 * is prohibited.
 */

#include "PlatformProperty.h"

/**
 * This function monitors the state of the str mode.
 * Notify all Transfer instances to enter or exit STR mode.
 *
 * @param propvalue - The value of the vehicle property being monitored.
 *
 * @returns void
 */
VIRTUAL_PROPERTY(MONITOR_STR_STATE) {
    builder.toTask().onPropertyValueChange(
        VehicleProperty::AP_POWER_STATE_REPORT, VehicleArea::GLOBAL,
        [](const VehiclePropValue& propvalue) {
            if (propvalue.value.int32Values.size() == 2) {
                const VehicleApPowerStateReport powerStateReq =
                    static_cast<VehicleApPowerStateReport>(propvalue.value.int32Values[0]);

                if (powerStateReq == VehicleApPowerStateReport::ON) {
                    VHALOG.d("MONITOR_STR_STATE: all transfer exit str mode");
                    SIGNAL.exitStrMode();
                } else if (powerStateReq == VehicleApPowerStateReport::SHUTDOWN_PREPARE) {
                    VHALOG.d("MONITOR_STR_STATE: all transfer enter str mode");
                    SIGNAL.enterStrMode();
                } else {
                    VHALOG.d("MONITOR_STR_STATE: powerStateReq %d",toInt(powerStateReq));
                }
            } else {
                VHALOG.w("MONITOR_STR_STATE: AP_POWER_STATE_REQ value error(int32Values size = %lu)",
                      propvalue.value.int32Values.size());
            }
        });
}